import { MessageBox, Message  } from "element-ui"
import request from '@/utils/request'

export const tableDel = async (id, path, message) => {
  await MessageBox.confirm(`是否删除${message}`, {
    distinguishCancelAndClose: true,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
  })
    .then(() => {  // 点击确认
      request({
        url: path + id,
        method: 'delete'
      })
        .then(res => {
          if (res.data.success) {
            Message.success({
              message: '删除成功!'
            });
          } else {
            Message({
              type: 'error',
              message: '删除失败!'
            });
          }
        })
        .catch(() => {
          Message({
            type: 'error',
            message: '请求异常!'
          });
        })
    })
    .catch(() => {});  // 点击取消
}
